package com.schoolCommunity.util;

import com.schoolCommunity.entity.ConfessionWall;
import com.schoolCommunity.mapper.MemberMapper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Set;

//校验并过滤写入的表白墙数据
@Component
public class CheckInsertConfessionWall {

    @Resource
    private MemberMapper MemberMapper;


    public String checkInsertConfessionWall(ConfessionWall ConfessionWall) {

        //获取获取现在注册过的id
        Set<Long> allMemberIdForSet = MemberMapper.getAllMemberIdForSet();
        if (!allMemberIdForSet.contains(ConfessionWall.getMemberId()) || ConfessionWall.getMemberId() == null)
            return "用户ID为空或错误ID，数据错误";
        if (ConfessionWall.getMemberNickname().length() > 20 || ConfessionWall.getMemberNickname() == null)
            return "用户名昵称不能为空且不能长于20个字符";
        if (ConfessionWall.getTitle().length() > 60 || ConfessionWall.getTitle() == null)
            return "表白墙主题不能为空或长于60个字符";
        if (ConfessionWall.getText() == null)
            return "表白墙内容不能为空";

        return "数据安全";
    }

}
